package com.itheima.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.common.ResultData;
import com.itheima.domain.UmsMenu;
import com.itheima.manager.UmsMenuManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台菜单表 前端控制器
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@RestController
@RequestMapping("/menu")
@CrossOrigin(origins = "*")
public class UmsMenuController {

    @Autowired
    UmsMenuManager umsMenuManager;
    // 菜单分页查询
    @GetMapping("/list/{parentId}")
    public ResultData list(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "5") Integer pageSize,
                           @PathVariable("parentId") Integer parentId){
        return umsMenuManager.getListByPage(pageNum,pageSize,parentId);
    }

    // 添加后台菜单
    @PostMapping("/create")
    public ResultData create(@RequestBody UmsMenu umsMenu){
        return umsMenuManager.create(umsMenu);
    }

    // 删除后台菜单
    @PostMapping("/delete/{id}")
    public ResultData delete(@PathVariable("id") Integer id){
        return umsMenuManager.delete(id);
    }

    // 修改菜单显示状态
    @PostMapping("/updateHidden/{id}")
    public ResultData updateHidden(@PathVariable("id") Integer id, @RequestParam Integer hidden){
        return umsMenuManager.updateHidden(id,hidden);
    }

    // 根据ID获取菜单详情
    @GetMapping("/{id}")
    public ResultData getById(@PathVariable Integer id){
        return umsMenuManager.getById(id);
    }

    // 修改后台菜单
    @PostMapping("/update/{id}")
    public ResultData update(@PathVariable("id") Integer id,@RequestBody UmsMenu umsMenu){
        return umsMenuManager.update(umsMenu);
    }

    // 树形结构返回所有菜单列表
    @GetMapping("/treeList")
    public ResultData treeList(){
        return umsMenuManager.treeList();
    }
}

